#include <func.h>
#include "ThreadPool.h"
#include "Network.h"
#include "Task.h"

#define SPACES " \t\n"

// 任务如何获取MySQL连接？
void upload_file(void* arg, Thread* thead)
{
    Param* param = (Param*)arg;
    int epfd = param->epfd;
    int connfd = param->connfd;
    
    // 解析Req: 文件大小  sha256sum  服务器应该存储的路径
    long fsize = atol(strtok(param->req.value, SPACES));
    char* sha256sum = strtok(NULL, SPACES);
    char* path = strtok(NULL, SPACES);

    // 判断文件是否已经存在
    char stmt[1024];
    sprintf(stmt, "SELECT sha256sum FROM files WHERE sha256sum = '%s'", sha256sum);

    // 任务执行完毕
    free(param);
    epoll_add(epfd, connfd);
}
